#coding=utf-8
import glob
import jieba
import re
import json
from common.macro_data import MacroData
from database.db_handler import MysqlHander

'''
宏观数据入库
日期|类型|标题|url|site|
2022-02-11|100|银行间债券市场债券借贷业务管理办法(中国人民银行公告〔2022〕第1号）|http://www.pbc.gov.cnhttp://www.pbc.gov.cn/tiaofasi/144941/3581332/4469360/index.html|央行|
'''

class AddMacroData:
    def __init__(self, file):
        self.file = file
        self.macro_data = MacroData()

    def write_db(self, d):
        data = d.split("|")
        if len(data) == 0:
            return
        self.macro_data.add_macro_data(data[0], int(data[1]), data[2], data[3], data[4])
    
    def record(self):
        with open(self.file, 'r', encoding='utf-8') as f:
            self.data = f.readlines()
        for b in self.data:
            self.write_db(b)

if __name__ == '__main__':
    code = AddMacroData('./out/webdriver_hongguanshuju_yanghang')
    code.record()
